<template>
  <div>
    <h2>修改页面</h2>
    <table class="table table-bordered">
      <tr>
        <td>借款款项名称</td>
        <td>
          <input type="text" v-model="sdata.J_Name" />
        </td>
      </tr>
      <tr>
        <td>借款最高金额</td>
        <td>
          <input type="text" v-model="sdata.J_MaxMoney" />
        </td>
      </tr>
      <tr>
        <td>借款最高年限</td>
        <td>
          <input type="text" v-model="sdata.J_MaxYear" />
        </td>
      </tr>
      <tr>
        <td>利息编号</td>
        <td>
          <select v-model="sdata.L_id">
            <option value="0">--请选择--</option>
            <option v-for="b in list" :value="b.L_id">
              {{ b.L_Year }}年{{ b.L_LiXi * 100 }}%
            </option>
          </select>
        </td>
      </tr>
      <tr>
        <td>借款款项简介</td>
        <td><textarea v-model="sdata.J_Info"></textarea></td>
      </tr>
      <tr>
        <td></td>
        <td><input type="button" value="添加借款" @click="add" /></td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue';
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';
let router = useRouter();
let route = useRoute();

let data = reactive({
  sdata: {
    J_Name: '',
    J_MaxMoney: '',
    J_MaxYear: '',
    L_id: 0,
    J_Info: '',
  },
  list: {},
});
let { sdata, list } = toRefs(data);

onMounted(() => {
  Bind();
  Fan();
});
const Bind = () => {
  axios({
    url: 'http://localhost:64514/api/Jie/Bind',
    method: 'get',
  }).then((res) => {
    list.value = res.data.data;
  });
};
const Fan = () => {
  axios({
    url: 'http://localhost:64514/api/Jie/fan',
    method: 'get',
    params: {
      J_Id_: route.query.J_Id_,
    },
  }).then((res) => {
    sdata.value = res.data.data;
  });
};

const add = () => {
  axios({
    url: 'http://localhost:64514/api/Jie/gai',
    method: 'post',
    data: {
      J_Id_: route.query.J_Id_,
      J_Name: sdata.value.J_Name,
      J_MaxMoney: sdata.value.J_MaxMoney,
      J_MaxYear: sdata.value.J_MaxYear,
      L_id: sdata.value.L_id,
      J_Info: sdata.value.J_Info,
    },
  }).then((res) => {
    if (res.data.data > 0) {
      alert('修改成功');
      router.push('/show');
    } else {
      alert('修改失败');
      return;
    }
  });
};
</script>

<style scoped></style>
